package com.vv.exceptiontest.entry;

import com.vv.exceptiontest.domain.Student;
import com.vv.exceptiontest.testException.AgeOutOfBroundException;

import java.util.Scanner;

public class main {
    public static void main(String[] args) {
        Student stu = new Student();
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入姓名:");
        stu.setName(sc.nextLine());

        while(true) {
            try {
                System.out.println("请输入年龄:");
                String sage = sc.nextLine();
                int age = Integer.parseInt(sage);
                stu.setAge(age);
                break;
            } catch (NumberFormatException e) {
                System.out.println("请输入一个整数:");
            } catch (AgeOutOfBroundException e){
                String message = e.getMessage();
                System.out.println(message + "请输入正确范围的年龄:");
            }
        }
        System.out.println(stu.toString());
    }
}
